/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("PhysicalStock",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Entity.DomainModels;
using VOL.Domain.IServices;
using Microsoft.AspNetCore.Authorization;
using VOL.Domain.Dto;

namespace VOL.Domain.Controllers
{
    [AllowAnonymous]
    public partial class PhysicalStockController
    {
        private readonly IPhysicalStockService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public PhysicalStockController(
            IPhysicalStockService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }
        
        [HttpGet("GetMenu")]
        public async Task<IActionResult> GetMenu()
        {
            var menu = await _service.GetMenuTreeAsync();
            return Ok(menu);
        }
         
        [HttpGet("Search")]
        public async Task<IActionResult> Search([FromQuery] PhysicalStockSearchDto searchDto)
        {
            if (searchDto == null)
                return BadRequest("Search parameters are required");

            var result = await _service.SearchAsync(searchDto);
            return Ok(result);
        }
    }
}
